import { Controller, Get, Body, Post, Patch, ParseIntPipe, Param, Delete } from '@nestjs/common';
import { UserService } from '@src/services/user/user.service';
import { CreateUserDto } from './dto/create.user.dto';
import { UpdateUserDto } from './dto/update.user.dto';

@Controller('user')
export class UserController {
  constructor (
    private readonly userService: UserService,
  ) { }

  @Get()
  async userList(): Promise<any> {
    return await this.userService.userList();
  }

  @Get(':id')
  async userDetails(
    @Param('id', new ParseIntPipe()) id: number,
  ): Promise<any> {
    return await this.userService.userDetails(id);
  }

  @Post()
  async createUser(
    @Body() body: CreateUserDto
  ): Promise<any> {
    return await this.userService.createUser(body);
  }

  @Patch(':id')
  async modifyUser(
    @Param('id', new ParseIntPipe()) id: number,
    @Body() body: UpdateUserDto,
  ): Promise<any> {
    return await this.userService.modifyUser(id, body);
  }

  @Delete(':id')
  async deleteUser(
    @Param('id', new ParseIntPipe()) id: number
  ): Promise<any> {
    return await this.userService.deleteUser(id);
  }
}
